package router

import (
	"3-27zk/client/client"
	"3-27zk/client/enit"
	"3-27zk/common/proto/user"
	"github.com/gin-gonic/gin"
	"net/http"
)

func SendSms(c *gin.Context) {
	var data enit.SendSms
	err := c.ShouldBind(&data)
	if err != nil {
		c.JSON(http.StatusInternalServerError, &gin.H{
			"code": 500,
			"msg":  "失败",
			"data": err.Error(),
		})
		return
	}
	sms, err := client.SendSms(c, &user.SendSmsReq{
		Phone:  data.Phone,
		Soures: data.Soures,
	})
	if err != nil {
		c.JSON(http.StatusInternalServerError, &gin.H{
			"code": 500,
			"msg":  "失败",
			"data": err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, &gin.H{
		"code": 200,
		"msg":  "成功",
		"data": sms,
	})
}
func Login(c *gin.Context) {
	var data enit.Login
	err := c.ShouldBind(&data)
	if err != nil {
		c.JSON(http.StatusInternalServerError, &gin.H{
			"code": 500,
			"msg":  "失败",
			"data": err.Error(),
		})
		return
	}
	sms, err := client.Login(c, &user.LoginReq{
		Phone:    data.Phone,
		Password: data.Password,
		SmsCode:  data.SmsCode,
	})
	if err != nil {
		c.JSON(http.StatusInternalServerError, &gin.H{
			"code": 500,
			"msg":  "失败",
			"data": err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, &gin.H{
		"code": 200,
		"msg":  "成功",
		"data": sms,
	})
}
func OrderAdd(c *gin.Context) {
	var data enit.OrderAdd
	err := c.ShouldBind(&data)
	if err != nil {
		c.JSON(http.StatusInternalServerError, &gin.H{
			"code": 500,
			"msg":  "失败",
			"data": err.Error(),
		})
		return
	}
	add, err := client.OrderAdd(c, &user.OrderAddReq{
		UserId:   int64(data.UserId),
		Name:     data.Name,
		RoomType: int64(data.RoomType),
		People:   data.People,
		Times:    data.Times,
		Price:    float32(data.Price),
		Person:   data.Person,
		Types:    int64(data.Types),
	})
	if err != nil {
		c.JSON(http.StatusInternalServerError, &gin.H{
			"code": 500,
			"msg":  "失败",
			"data": err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, &gin.H{
		"code": 200,
		"msg":  "成功",
		"data": add,
	})
}
func OrderList(c *gin.Context) {
	add, err := client.OrderList(c, &user.OrderListReq{})
	if err != nil {
		c.JSON(http.StatusInternalServerError, &gin.H{
			"code": 500,
			"msg":  "失败",
			"data": err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, &gin.H{
		"code": 200,
		"msg":  "成功",
		"data": add,
	})
}
